package com.bootdo.blog.dao;

import com.bootdo.blog.domain.PlantingDO;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-03-07 10:38:32
 */
@Mapper
public interface PlantingMapper {

	@Select("select `plant_id`, `base_number`, `base_title`, `base_address`, `planting_area`, `base_manager`, `regional_climate`, `sunshine_time`, `temp_dif` from tb_planting where plant_id = #{id}")
	PlantingDO get(Integer plantId);
	
	@Select("<script>" +
	"select * from tb_planting " + 
			"<where>" + 
		  		  "<if test=\"plantId != null and plantId != ''\">"+ "and plant_id = #{plantId} " + "</if>" + 
		  		  "<if test=\"baseNumber != null and baseNumber != ''\">"+ "and base_number = #{baseNumber} " + "</if>" + 
		  		  "<if test=\"baseTitle != null and baseTitle != ''\">"+ "and base_title = #{baseTitle} " + "</if>" + 
		  		  "<if test=\"baseAddress != null and baseAddress != ''\">"+ "and base_address = #{baseAddress} " + "</if>" + 
		  		  "<if test=\"plantingArea != null and plantingArea != ''\">"+ "and planting_area = #{plantingArea} " + "</if>" + 
		  		  "<if test=\"baseManager != null and baseManager != ''\">"+ "and base_manager = #{baseManager} " + "</if>" + 
		  		  "<if test=\"regionalClimate != null and regionalClimate != ''\">"+ "and regional_climate = #{regionalClimate} " + "</if>" + 
		  		  "<if test=\"sunshineTime != null and sunshineTime != ''\">"+ "and sunshine_time = #{sunshineTime} " + "</if>" + 
		  		  "<if test=\"tempDif != null and tempDif != ''\">"+ "and temp_dif = #{tempDif} " + "</if>" + 
		  			"</where>"+ 
			" <choose>" + 
	            "<when test=\"sort != null and sort.trim() != ''\">" + 
	                "order by ${sort} ${order}" + 
	            "</when>" + 
				"<otherwise>" + 
	                "order by plant_id desc" + 
				"</otherwise>" + 
	        "</choose>"+
			"<if test=\"offset != null and limit != null\">"+
			"limit #{offset}, #{limit}" + 
			"</if>"+
			"</script>")
	List<PlantingDO> list(Map<String, Object> map);
	
	@Select("<script>" +
	"select count(*) from tb_planting " + 
			"<where>" + 
		  		  "<if test=\"plantId != null and plantId != ''\">"+ "and plant_id = #{plantId} " + "</if>" + 
		  		  "<if test=\"baseNumber != null and baseNumber != ''\">"+ "and base_number = #{baseNumber} " + "</if>" + 
		  		  "<if test=\"baseTitle != null and baseTitle != ''\">"+ "and base_title = #{baseTitle} " + "</if>" + 
		  		  "<if test=\"baseAddress != null and baseAddress != ''\">"+ "and base_address = #{baseAddress} " + "</if>" + 
		  		  "<if test=\"plantingArea != null and plantingArea != ''\">"+ "and planting_area = #{plantingArea} " + "</if>" + 
		  		  "<if test=\"baseManager != null and baseManager != ''\">"+ "and base_manager = #{baseManager} " + "</if>" + 
		  		  "<if test=\"regionalClimate != null and regionalClimate != ''\">"+ "and regional_climate = #{regionalClimate} " + "</if>" + 
		  		  "<if test=\"sunshineTime != null and sunshineTime != ''\">"+ "and sunshine_time = #{sunshineTime} " + "</if>" + 
		  		  "<if test=\"tempDif != null and tempDif != ''\">"+ "and temp_dif = #{tempDif} " + "</if>" + 
		  			"</where>"+ 
			"</script>")
	int count(Map<String, Object> map);
	
	@Insert("insert into tb_planting (`base_number`, `base_title`, `base_address`, `planting_area`, `base_manager`, `regional_climate`, `sunshine_time`, `temp_dif`)"
	+ "values (#{baseNumber}, #{baseTitle}, #{baseAddress}, #{plantingArea}, #{baseManager}, #{regionalClimate}, #{sunshineTime}, #{tempDif})")
	int save(PlantingDO planting);
	
	@Update("<script>"+ 
			"update tb_planting " + 
					"<set>" + 
		            "<if test=\"plantId != null\">`plant_id` = #{plantId}, </if>" + 
                    "<if test=\"baseNumber != null\">`base_number` = #{baseNumber}, </if>" + 
                    "<if test=\"baseTitle != null\">`base_title` = #{baseTitle}, </if>" + 
                    "<if test=\"baseAddress != null\">`base_address` = #{baseAddress}, </if>" + 
                    "<if test=\"plantingArea != null\">`planting_area` = #{plantingArea}, </if>" + 
                    "<if test=\"baseManager != null\">`base_manager` = #{baseManager}, </if>" + 
                    "<if test=\"regionalClimate != null\">`regional_climate` = #{regionalClimate}, </if>" + 
                    "<if test=\"sunshineTime != null\">`sunshine_time` = #{sunshineTime}, </if>" + 
                    "<if test=\"tempDif != null\">`temp_dif` = #{tempDif}, </if>" + 
          					"</set>" + 
					"where plant_id = #{plantId}"+
			"</script>")
	int update(PlantingDO planting);
	
	@Delete("delete from tb_planting where plant_id =#{plantId}")
	int remove(Integer plant_id);
	
	@Delete("<script>"+ 
			"delete from tb_planting where plant_id in " + 
					"<foreach item=\"plantId\" collection=\"array\" open=\"(\" separator=\",\" close=\")\">" + 
						"#{plantId}" + 
					"</foreach>"+
			"</script>")
	int batchRemove(Integer[] plantIds);
}
